﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Experts.Framework.Mapping
{
    /// <summary>
    /// 静态类的静态方法，第一个参数前加个this
    /// </summary>
    public static class MappingExtend
    {
        public static string GetMappingName<T>(this T t) where T:MemberInfo
        {
            if (t.IsDefined(typeof(AbstractMappingAttribute), true))
            {
                AbstractMappingAttribute attribute = t.GetCustomAttribute<AbstractMappingAttribute>();
                return attribute.GetName();
            }
            else
            {
                return t.Name;
            }
        }
        /// <summary>
        /// 从一堆属性里面，去掉标记了Key的属性
        /// </summary>
        /// <param name="props"></param>
        /// <returns></returns>
        public static IEnumerable<PropertyInfo> FilterKey(this IEnumerable<PropertyInfo> props)
        {
            return props.Where(p => !p.IsDefined(typeof(KeyAttribute), true));
        }
    }
}
